home *** CD-ROM | disk | FTP | other *** search
- TITLE PROCED
-
-
-
- ;Routines
-
- public FIXUP_COMMAND_LINE,GET_LINE_LENGTH,GLOOP,TABS2SPACES,TABLOOP
- public TABS_DONE,UPPER_CASE,LCLOOP,LSKIP,GET_D_SWITCH,D_NOT_FOUND
- public MOVE_PARAMETERS,MOVE_FIRST,MOVE_SECOND,ONLY_ONE,PAR_ERROR
- public PRINT_FILENAME,PRINT_CRLF,MOVE_PNAME,LOOK_FOR_COLON,P1,MOVE_P
- public TO_BIG_ERROR,APPEND_STAR_DOT_STAR,APPEND_ERROR,SKIP_SPACES
-
- ;Variables
-
- public CRLF,STAR_DOT_STAR
-
- G GROUP CODE
- CODE SEGMENT PUBLIC
- ASSUME CS:G, DS:G, ES:G, SS:G
-
- SPACE EQU 20H
- NULL EQU 0
- MAX_NAME_LENGTH EQU 80
- CR EQU 0DH
- LF EQU 0AH
- TAB EQU 9
- DISPLAY_CHAR EQU 2
- DISPLAY_STRING EQU 9
-
- CRLF DB CR, LF, "$"
- STAR_DOT_STAR DB "\*.*", NULL
-
- ;--------------------------------------------------------------------
-
- FIXUP_COMMAND_LINE PROC
- ; This routine changes all the tabs on the command line to single spaces,
- ; and changes all lower case to upper case.
- ; call: es:80h -> command line
- ; return: cx = number of characters on the command line including the cr.
-
- MOV SI, 81H
- CALL GET_LINE_LENGTH
- CALL TABS2SPACES
- CALL UPPER_CASE
- RET
- FIXUP_COMMAND_LINE ENDP
-
- ;--------------------------------------------------------------------
-
- GET_LINE_LENGTH PROC
- ; Get the length of this line and change the cr to a space.
- ; call: es:si -> the start of the line ending with a cr.
- ; return: cx = number characters on the line counting the cr.
-
- CLD
- MOV DI, SI
- MOV AL, CR
- XOR CX, CX
- GLOOP:
- INC CX
- SCASB
- JNZ GLOOP
-
- MOV [DI-1], BYTE PTR SPACE ; change the cr to a space
- RET
- GET_LINE_LENGTH ENDP
-
- ;--------------------------------------------------------------------
-
- TABS2SPACES PROC
- ; Change all tabs to spaces on the line.
- ; call: es:si -> the start of the line
- ; cx = number characters on the line
- ; cld (up direction)
- ; ds = es
-
- PUSH CX
-
- MOV DI, SI
- MOV AL, TAB
-
- TABLOOP:
- REPNZ SCASB
- JNZ TABS_DONE
-
- MOV [DI-1], BYTE PTR SPACE
- JCXZ TABS_DONE
- JMP TABLOOP
-
- TABS_DONE:
- POP CX
- RET
- TABS2SPACES ENDP
-
- ;--------------------------------------------------------------------
-
- UPPER_CASE PROC
- ; Convert all lower case to upper case on this line.
- ; call: es:si -> the start of the line
- ; cx = the number of characters on the line
- ; ds = es
-
- PUSH CX
- PUSH SI
-
- MOV DI, SI
-
- LCLOOP:
- LODSB
-
- CMP AL, "a"
- JB LSKIP
- CMP AL, "z"
- JA LSKIP
-
- AND AL, 11011111B
-
- LSKIP:
- STOSB
- LOOP LCLOOP
-
- POP SI
- POP CX
- RET
- UPPER_CASE ENDP
-
- ;--------------------------------------------------------------------
-
- GET_D_SWITCH PROC
- ; This routine looks for "/D " switch on the command line.
- ; Its assumed that the command line has been "fixed up".
- ; After it has found the switch it changes it to spaces.
- ; call: si -> command line
- ; cx = number of character on the command line including the cr
- ; return: al = 0 if no "d" switch
- ; al = 1 if the "d" switch was found
- PUSH CX
-
- MOV DI, SI
- MOV AL, '/'
- REPNZ SCASB
- JNZ D_NOT_FOUND
-
- MOV [DI-1], BYTE PTR SPACE
-
- CALL SKIP_SPACES
-
- MOV AL, 'D'
- SCASB
- JNZ D_NOT_FOUND
-
- MOV AL, SPACE
- SCASB
- JNZ D_NOT_FOUND
-
- MOV [DI-2], BYTE PTR SPACE
- MOV AL, 1
- POP CX
- RET
-
- D_NOT_FOUND:
- XOR AL, AL
- POP CX
- RET
- GET_D_SWITCH ENDP
-
- ;--------------------------------------------------------------------
-
- MOVE_PARAMETERS PROC
- ; Move the two filenames from the command line to two buffers. End the
- ; two filenames with a null.
- ; Assume that the switch has been changed to spaces and the cr has been
- ; replaced with a space.
- ; call: dx -> location to put the first filename
- ; bx -> location to put the second filename
- ; 81h -> command line
- ; cx = line length
- ; return: carry = 1 if and error ocurred and al = error code
- ; if error, al = 7 - "no parameters"
-
- MOV DI, 81H
- CALL SKIP_SPACES
- CMP CX, 1
- JZ PAR_ERROR
-
- MOV SI, DI
- MOV DI, DX
-
- MOVE_FIRST:
- MOVSB
- CMP [SI], BYTE PTR SPACE
- LOOPNZ MOVE_FIRST
-
- MOV AL, NULL ; end each name with a null
- STOSB
-
- MOV DI, SI
-
- CALL SKIP_SPACES
- CMP CX, 1
- JZ ONLY_ONE
-
- MOV SI, DI
- MOV DI, BX
-
- MOVE_SECOND:
- MOVSB
- CMP [SI], BYTE PTR SPACE
- LOOPNZ MOVE_SECOND
-
- MOV AL, NULL
- STOSB
-
- CLC
- RET
-
- ONLY_ONE:
- MOV CX, 20 ; store 20 null for the second name
- MOV AL, NULL
- REP STOSB
- CLC
- RET
-
- PAR_ERROR:
- STC
- MOV AL, 7
- RET
- MOVE_PARAMETERS ENDP
-
- ;--------------------------------------------------------------------
-
- PRINT_FILENAME PROC
- ; Print an ascii string then print a cr, lf.
- ; call: si -> first character of the ascii string to be printed ending with a
- ; null
-
- LODSB
- CMP AL, NULL
- JZ PRINT_CRLF
-
- MOV DL, AL
- MOV AH, DISPLAY_CHAR
- INT 21H
-
- JMP PRINT_FILENAME
-
- PRINT_CRLF:
- MOV AH, DISPLAY_STRING
- LEA DX, CRLF
- INT 21H
-
- RET
- PRINT_FILENAME ENDP
-
- ;--------------------------------------------------------------------
-
- MOVE_PNAME PROC
- ; This procedure will move a "pname" to the last position of another name.
- ; The last position is either:
- ; 1. after the last "\"
- ; 2. after the ":"
- ; 3. at the first location.
- ; call: si -> pname to move
- ; di -> start of a name ending with a null.
- ; cld (up direction)
- ; return: carry = 1 if the name was to big and al = error code of 15
-
- MOV BX, DI
-
- MOV CX,MAX_NAME_LENGTH ; Go to the end of the name
- MOV AL,NULL
- REPNZ SCASB
- JNZ TO_BIG_ERROR
-
- DEC DI
- DEC DI ; calculate the size of the name
- MOV AX, MAX_NAME_LENGTH
- SUB AX, CX
- MOV CX, AX
-
- STD ; look for a "\"
- MOV AL, "\"
- REPNZ SCASB
- JZ P1
-
- LOOK_FOR_COLON:
- MOV DI, BX
- CMP [DI+1], BYTE PTR ":"
- JNZ MOVE_P
-
- P1:
- INC DI
- INC DI
-
- MOVE_P:
- CLD
- MOV CX, 13
- REP MOVSB
- MOV AL, NULL
- STOSB
- CLC
- RET
-
- TO_BIG_ERROR:
- MOV AL, 15
- STC
- RET
- MOVE_PNAME ENDP
-
- ;--------------------------------------------------------------------
-
- APPEND_STAR_DOT_STAR PROC
- ; Append "\*.*" to the end of a name
- ; call: ds:si -> the beginning of a name ending with a null.
- ; es = ds
- ; cld (up direction)
- ; return: carry = 1 if the name excedes the max. name length and al =
- ; error code of 15
-
- MOV CX, MAX_NAME_LENGTH
- MOV DI, SI
- MOV AL, NULL
- REPNZ SCASB
- JCXZ APPEND_ERROR
-
- DEC DI
- LEA SI, STAR_DOT_STAR
- MOV CX, 5
- REP MOVSB
-
- CLC
- RET
-
- APPEND_ERROR:
- MOV AL, 15
- STC
- RET
- APPEND_STAR_DOT_STAR ENDP
-
- ;--------------------------------------------------------------------
-
- SKIP_SPACES PROC
- ; call: es:di -> at a string
- ; cx = max. number of characters to skip
- ; return: es:di -> first non space character
-
- MOV AL, SPACE
-
- REPZ SCASB
-
- INC CX
- DEC DI
- RET
- SKIP_SPACES ENDP
-
- ;--------------------------------------------------------------------
-
- CODE ENDS
- END